# !/usr/bin/python3
# -*- coding: utf-8 -*-

import tensorflow as tf

"""
@Author         :  cwy
@Version        :  
------------------------------------
@File           :  ai_lab.py
@Description    :  
@CreateTime     :  2021/1/13 2:57 下午
------------------------------------
@ModifyTime     :  
"""

'''

'''

'''
准备数据
搭建网络
优化参数
应用网络
'''

'''
给鸢尾花分类
'''

x = tf.constant([[1, 2, 3],
                 [2, 2, 3]])
print(x)
# -------------------------------------------------
features = tf.constant([12, 23, 10, 17])
labels = tf.constant([0, 1, 1, 0])
dataset = tf.data.Dataset.from_tensor_slices((features, labels))
print(dataset)
for element in dataset:
    print(element)

# -------------------------------------------------
with tf.GradientTape() as tape:
    w = tf.Variable(tf.constant(3.0))
    loss = tf.pow(w, 2)
grad = tape.gradient(loss, w)
print(grad)

# -------------------------------------------------
classes = 3
labels = tf.constant([1, 0, 2])
output = tf.one_hot(labels, depth=classes)
print(output)

# -------------------------------------------------
y = tf.constant([1.01, 2.01, -0.66])
y_pro = tf.nn.softmax(y)
print(y_pro)

# -------------------------------------------------
print('返回最大值索引号----------------')
import numpy as np

test = np.array([[1, 2, 3], [2, 3, 4], [5, 4, 3], [8, 7, 2]])
print(test)
print(tf.argmax(test, axis=0))
print(tf.argmax(test, axis=1))

# 加载鸢尾花数据集-------------------------------------------------
from sklearn import datasets
from pandas import DataFrame
import pandas as pd

x_data = datasets.load_iris().data
y_data = datasets.load_iris().target
print(y_data)

# -------------------------------------------------
for i in range(5):
    for ii in range(10):
        print(ii)
